package tp.ui.menu.client;

import java.util.List;

import tp.model.Ticket;
import tp.ui.menu.pattern.SousMenu;
import tp.util.DataSingleton;
import tp.util.DateTool;
import tp.util.Reader;

public class DeleteReservation extends SousMenu {

	public DeleteReservation() {
		super("Supprimer une reservation");
	}

	@Override
	public void execute() {

		List<Ticket> tickets = DataSingleton
				.getInstance()
				.getFacade()
				.clientGetAllActiveTickets(
						DataSingleton.getInstance().getClient());

		if (tickets != null) {
			System.out.println("Listde de mes tickets : (" + tickets.size()
					+ ")");

			int i = 1;
			for (Ticket ticket : tickets) {
				System.out.println("\t"
						+ i
						+ ":"
						+ ticket.getTrajet().getDepart().getNom()
						+ "-"
						+ ticket.getTrajet().getArrivee().getNom()
						+ " le "
						+ DateTool.printDate(ticket.getTrajet().getDate(),
								DateTool.DATE_FORMAT));
				i++;
			}

			int select = Reader.lireInt(1, tickets.size());
			System.out.println("selectionnez le ticket a modifier : ");
			Ticket selected = tickets.get(select - 1);

			DataSingleton.getInstance().getFacade().ticketDelete(selected);
		} else {
			System.out.println("Il n'y a pas de ticket a afficher");
		}
	}
}
